package com.zking.ssm.NH.controller;

import com.zking.ssm.NH.model.tbUser;
import com.zking.ssm.NH.service.ITbUserService;
import com.zking.ssm.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author NH
 * @Date 2021/1/20/0020 19:31
 */

@Controller
@RequestMapping("/admin")
public class TbUserController {
    @Autowired
    private ITbUserService tbUserService;

    private tbUser tbUser;

    @RequestMapping("/doLogin")
    @ResponseBody
    public JsonData doLogin(tbUser tbUser) {
        JsonData jsonData = new JsonData();

        tbUser u = tbUserService.selectAdmin(tbUser);
        if (null == u || !u.getPassword().equals(tbUser.getPassword())) {
            jsonData.setCode(-1);
            jsonData.setMessage("帐号或密码错误");
        } else {
            Map<String, Object> claims = new HashMap<String, Object>();
            claims.put("username", u.getUsername());
//            String jwt = JwtUtils.createJwt(claims, JwtUtils.JWT_WEB_TTL);
//            System.out.println(jwt);
//            HttpServletResponse response = ServletActionContext.getResponse();
//            response.setHeader(JwtUtils.JWT_HEADER_KEY, jwt);

            jsonData.setCode(0);
            jsonData.setMessage("登陆成功");

//            ServletActionContext.getRequest().getSession().getId();
        }
        return jsonData;
    }
}
